{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2020-10-20T01:42:45.378700Z",
     "start_time": "2020-10-20T01:42:43.862854Z"
    }
   },
   "outputs": [],
   "source": [
    "import torch\n",
    "import matplotlib.pyplot as plt\n",
    "import numpy as np\n",
    "%matplotlib inline"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2020-10-20T02:19:18.552658Z",
     "start_time": "2020-10-20T02:19:18.543242Z"
    }
   },
   "outputs": [],
   "source": [
    "in_channels,out_channels=5,10\n",
    "width,height=100,100\n",
    "kernal_size=3\n",
    "batch_size=1\n",
    "input_n= torch.randn(batch_size,in_channels,width,height)\n",
    "conv_layer=torch.nn.Conv2d(in_channels,out_channels,kernel_size=kernal_size)\n",
    "conv_layer=torch.nn.Conv2d(1,1,kernel_size=3,padding=1,bias=False,stride=2)\n",
    "conv=torch.Tensor([1,2,3,4,5,6,7,8,9]).view(1,1,3,3)\n",
    "#conv.data\n",
    "conv_layer.weight.data=conv.data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2020-10-20T02:18:43.255195Z",
     "start_time": "2020-10-20T02:18:43.239360Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "torch.Size([1, 5, 100, 100])"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "input_n.shape"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2020-10-20T02:19:41.406884Z",
     "start_time": "2020-10-20T02:19:41.399214Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Parameter containing:\n",
       "tensor([[[[1., 2., 3.],\n",
       "          [4., 5., 6.],\n",
       "          [7., 8., 9.]]]], requires_grad=True)"
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "conv_layer.weight"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2020-10-20T02:22:25.267072Z",
     "start_time": "2020-10-20T02:22:25.258713Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "tensor([[[[1., 2., 3., 4.],\n",
       "          [5., 6., 2., 5.],\n",
       "          [3., 5., 3., 5.],\n",
       "          [6., 7., 3., 2.]]]])"
      ]
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "input_n2=torch.Tensor([1,2,3,4,5,6,2,5,3,5,3,5,6,7,3,2]).view(1,1,4,4)\n",
    "input_n2.data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2020-10-20T02:24:02.518295Z",
     "start_time": "2020-10-20T02:24:02.509903Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "tensor([[[[6.]]]])"
      ]
     },
     "execution_count": 24,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "maxpool=torch.nn.MaxPool2d(kernel_size=3)\n",
    "o=maxpool(input_n2)\n",
    "o.data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
